import { observable, action } from 'mobx';
import {WeaTableNew,WeaForm} from 'comsMobx'
const {TableStore} = WeaTableNew;
import { WeaTools,WeaLocaleProvider } from 'ecCom';
import {message,Modal} from 'antd';
const confirm = Modal.confirm;
import {toJS} from "mobx"
import * as Apis from "../apis/project"
const getLabel = WeaLocaleProvider.getLabel;


export  class RelateListStore{
    @observable title = getLabel(1044,"相关流程");

	datakey = "";
	@observable tableStore = new TableStore();
	targetid = "";
	@observable type = "";

    @observable visible = false;
    @observable modalStyle = {width:'900px', height:'500px'};
    @observable form = new WeaForm();
    noticeCondition = [];
    @observable visibleDatas = {  //版本比较数据
        compareTitle:"",
        visibleData:[],
        visibleLoading:false
    };
    @observable compareVisible = false;

	
    @action 
	reLoad = (tableStore) => {
        tableStore.getDatas(tableStore.dataKey, tableStore.current,tableStore.pageSize,tableStore.sortParams)
    }
    @action 
    handleRelateDialog = (bool,type,id ,params={}) =>{
		this.visible = bool;
		if(bool){
            this.type = type;
            this.targetid = id;
            if(type=="request"){
                this.title = getLabel(1044,"相关流程")
                this.doSearch();
                this.modalStyle = {width:'900px', height:'500px'};
            }else if(type == "doc"){
                this.title = getLabel(857,"相关文档");
                this.doSearch();
                this.modalStyle = {width:'900px', height:'500px'};
            }else if(type == "cowork"){
                this.title = getLabel(83911,"相关协作");
                this.doSearch();
                this.modalStyle = {width:'900px', height:'500px'};
            }else if(type == "notice"){
                this.title = getLabel(1348,"通知成员");
                this.modalStyle = {width:'600px', height:'250px'};
                this.getNoticeInfo();
            }else if(type =="history"){
                this.title = getLabel(18500,"历史版本");
                this.doSearch();
                this.modalStyle = {width:'900px', height:'500px'};
            }else if(type == "log"){
                this.title = getLabel(83926,"任务日志");
                this.doSearch();
                this.modalStyle = {width:'900px', height:'500px'};
            }
            
		}
    }
    doSearch=(params={})=>{
        this.tableStore = new TableStore();
        const newParams = {dsptype:this.type,prjid:this.targetid,...params};
        Apis.getPrjDspList(newParams).then(data=>{
            this.tableStore.getDatas(data.sessionkey,  params.current || 1);
			this.dataKey = data.sessionkey;
        })
    }
    noticeMember=()=>{
        const formParams = this.form.getFormParams();
        this.form.validateForm().then(f=>{
            if(f.isValid){
               const newParams = {method:"tellmember",prjid:this.targetid,...formParams};
               Apis.doPlanOpt(newParams).then(data=>{
                    this.handleRelateDialog(false);
                    message.success(getLabel(1348,"通知成员")+getLabel(84565,"成功！"))
               })
            }else{
                f.showErrors();
               	// Modal.warning({
                //     title: getLabel(15172,"系统提示"),
                //     content: getLabel(15859,"必要信息不完整！"),
                // });
            }
        });
    }
    compareVersion=(bool,ids)=>{
        this.compareVisible = bool;
        this.visibleDatas.visibleLoading = true;
        if(bool){
            Apis.getPrjHisCompare({prjid:this.targetid,versions:ids}).then(data=>{
                this.visibleDatas = {  //版本比较数据
                    compareTitle:data.titlename,
                    visibleData:data.datas,
                    visibleLoading:false
                };
            })
        }
    }
    getNoticeInfo=(params)=>{
        this.form = new WeaForm();
        Apis.getNoticeMember({prjid:this.targetid}).then(data=>{
            this.noticeCondition = [
                {
                    "title": getLabel(1361,"基本信息"),
                    "items": [
                        {
                            "labelcol": 5,
                            "colSpan": 2,
                            "value": "1",
                            "conditionType": "BROWSER",
                            "domkey": [
                                "hrms"
                            ],
                            "browserType": "17",
                            "fieldcol": 16,
                            "label": getLabel(383861,"通知对象"),
                            'rules': 'required|string', // 校验规则
                            "browserConditionParam": {
                                "isAutoComplete": 1,
                                "isDetail": 0,
                                "title": getLabel(839,"多人力资源"),
                                "linkUrl": "",
                                "isMultCheckbox": false,
                                "hasAdd": false,
                                "viewAttr": 3,
                                "dataParams": {},
                                "hasAdvanceSerach": true,
                                "isSingle": false,
                                "replaceDatas": [],
                                "type": "17",
                                ...data
                            },
                        }, {
                            "labelcol": 5,
                            "colSpan": 2,
                            "viewAttr": 3,
                            "length": 1000,
                            "value": "",
                            "conditionType": "INPUT",
                            'rules': 'required|string', // 校验规则
                            "domkey": [
                                "noticetitle"
                            ],
                            "fieldcol": 16,
                            "label": getLabel(383862,"通知标题")
                        }, {
                            "labelcol": 5,
                            "colSpan": 2,
                            "viewAttr": 3,
                            "value": "",
                            "conditionType": "TEXTAREA",
                            'rules': 'required|string', // 校验规则
                            "domkey": [
                                "noticecontent"
                            ],
                            "fieldcol": 16,
                            "label": getLabel(383863,"通知内容")
                        }
                    ],
                    "defaultshow": true
                }
            ];
            this.form && !this.form.isFormInit && this.form.initFormFields(this.noticeCondition);
        })
    }

}